import Vue from 'vue';
import VueRouter from 'vue-router'
import authRouter, {
    adminRouter
} from './authRouter';
import Login from '../views/Login.vue'
import Manage from '../views/Manage.vue'
import AdminManage from '../views/AdminManage.vue'
Vue.use(VueRouter);
const router = new VueRouter({

    routes: (() => {
        const userInfo = JSON.parse(localStorage.getItem("userInfo")) || {}
        // console.log("this.isLogin",JSON.parse(userInfo));
        if (Object.keys(userInfo).length > 0 && Number(userInfo?.isStudentManage) === 1&&userInfo.radio===1) {
            const adminRouterList = adminRouter()
            console.log(1111);
            return [{
                path: "/login",
                component: Login,
            }, {
                path: "/",
                redirect: '/AdminManageHome'
            }, {
                path: "/AdminManage",
                redirect: '/AdminManageHome'
            }, {
                path: '/AdminManageHome',
                component: AdminManage,
                // 注册子路由
                children: adminRouterList,
                meta: {
                    requiresAuth: true
                }
            }]

        }else if(Object.keys(userInfo).length > 0 && Number(userInfo?.isStudentManage) === 2&&userInfo.radio===2){
            const adminRouterList = adminRouter()
            console.log(222);
            return [{
                path: "/login",
                component: Login,
            }, {
                path: "/",
                redirect: '/AdminManageHome'
            }, {
                path: "/AdminManage",
                redirect: '/AdminManageHome'
            }, {
                path: '/AdminManageHome',
                component: AdminManage,
                // 注册子路由
                children: adminRouterList,
                meta: {
                    requiresAuth: true
                }
            }]
        }
        return [{
                path: "/login",
                component: Login,
            },
            {
                path: "/",
                redirect: '/login'
            },
            {
                path: "/manage",
                redirect: '/manage/home'
            },
            {
                path: '/manage/home',
                component: Manage,
                // 注册子路由
                children: authRouter,
                meta: {
                    requiresAuth: true
                }
            },

        ]
    })()
})

export default router;